/**
 * Created by Amy on 2018/8/2.
 */
var userNameOld = '';

$(function () {
    //解析url中的参数
    var url = window.location.href;
    var index = url.indexOf("?");
    var str = url.substring(index + 1);
    var strs = str.split("&");
    var userName = strs[0].split("=")[1];
    //isLoginFun();
    passwordHeader(userName);
});

function designPasswordQuestion() {
    var As1 = $("#AS1").val();
    var As2 = $("#AS2").val();
    if (!As1) {
        layer.msg("请输入问题1的答案", {icon: 2});
        return;
    }
    if (!As2) {
        layer.msg("请输入问题2的答案", {icon: 2});
        return;
    }
    var Q1 = $("#Question1").val();
    var Q2 = $("#Question2").val();
    var da = {
        "user": "admin",
        "question1": Q1,
        "question2": Q2,
        "answer1": As1,
        "answer2": As2
    }
    commonAjaxPost(true, "/admin/designPasswordQuestion", da, function (result) {
        if (result.code === '666') {
            layer.msg(result.message, {icon: 1})
            //清空id为AS1和AS2的标签的值
            $("#AS1").val("");
            $("#AS2").val("");
        } else {
            layer.msg(result.message, {icon: 2})
        }
    })

}

//头部导航栏
function passwordHeader(userName) {
    var urlPath = UrlSearch();
    var header = "";
    header += '<div class="header headerFixed">\n' +
        '        <div class="my-container clearfix">\n' +
        '            <div id="ctl01_divreturn" class="logo pull-left">\n';
    header += '<a href="javascript:history.go(-1)" class="hover" id="hrefPGoBack"><em class="icon returnicon"></em>返回</a>';
    header += '</div>\n' +
        '            <div class="user-wrapper pull-right" id="userbutton">\n' +
        '                <dl class="my-question pull-left">\n' +
        '                    <dt class="box user-info">\n';
    if (userName != null && userName !== "") {
        header += '                        <a class="user-name" onclick="dataScreen()"><i class="icon questions-icon"><em></em></i><span>数据大屏</span></a>\n';
    } else {
        header += '                        <a class="user-name" href="myQuestionnaires.html"><i class="icon questions-icon"><em></em></i><span>我的项目</span></a>\n';
    }
    header +=
        '                    </dt>\n' +
        '                    <dd class="line"></dd>\n' +
        '                </dl>\n' +
        '                <dl class="user-info pull-left">\n' +
        '                    <dt class="icon user-icon"><em></em></dt>\n' +
        '                    <dd class="spinner-list">\n' +
        '                        <a href="javascript:void(0)" class="user-name">'
        +
        '                           <span id="ctl01_lblUserName"style="text-align:center">' + getCookie("userName") + '</span>'
        +
        '                        </a>&nbsp;&nbsp;|&nbsp;&nbsp;<a class="user-name" href="TenantsManage.html?userName=' + getCookie("userName") + '" id="gotoUserManage">租户管理</a>\n'
        +
        '                        </a>&nbsp;&nbsp;|&nbsp;&nbsp;<a class="user-name" href="designPassworcQuestions.html?userName=' + getCookie("userName") + '" id="gotoUserManage2">密保设置</a>\n'
        +
        '                    </dd>\n' +
        '                </dl>\n' +
        '                <dl id="ctl01_hrefWjxout" class="user-info pull-left IE-8">\n'
        +
        '                    <a class="user-name" href="javascript:void(0)" onclick=\'logOut()\'>\n'
        +
        '                        <dt class="icon out-icon"></dt>\n' +
        '                        <dd class="spinner-list" style="line-height: 3.2!important;">\n'
        +
        '                            <span>退出</span>\n' +
        '                        </dd>\n' +
        '                    </a>\n' +
        '                </dl>\n' +
        '            </div>\n' +
        '        </div>\n' +
        '    </div>';
    $(".header").html(header);

}

//跳转到数据大屏
function dataScreen() {
    window.location.href = "http://localhost:8080/#/data?id=" + getCookie("userName");
}

